<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%@ taglib prefix="c"  uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>添加权限组</title>
<style type="text/css">
#formtable{ margin:20px 20px 0px 20px; border:dashed #03F 1px; font-size:14px; float:left;}
#buttondiv{ margin:20px 0px 0px 0px;}
</style>
<link type="text/css" rel="stylesheet" href="<%=request.getContextPath()%>/js/dhtmlxtree/dhtmlxtree.css"  />
<link type="text/css" rel="stylesheet" href="<%=request.getContextPath()%>/css/Global.css"  />   
<script src="<%=request.getContextPath()%>/js/dhtmlxtree/dhtmlxcommon.js"></script>
<script src="<%=request.getContextPath()%>/js/dhtmlxtree/dhtmlxtree.js"></script>

<script type="text/javascript">
function Verify(thisform)
{
	document.getElementById("perms").value = tree.getAllCheckedBranches();
	vau groupname = thisform.permgroupname.value.replace(/\s+/g,"");
	if (groupname.length == 0)
	{
		alert("权限组名称不能为空！");
		return false;
	}

	return true;
}
 
 
</script>
</head>
<body>
<div class="pagetitlediv" align="center">
新增权限组
</div>
<form name="permgroup" action="${contextpath}/security/permissiongroup_dealAdd.action" method="post" onsubmit="return Verify(this)">
<input id="perms" name="permissions" type="hidden" value="" />
<table id="formtable">		
	<tr>
  	<td width="112">权限组名称：</td><td width="316"><input name="permgroupname" type="text" size="35" /></td>
  </tr>
  <tr>
    <td>权限组简介：</td><td align="right">是否允许分配子权限：<input name="enableallot" type="checkbox" /></td>
	</tr>
  <tr>
  	<td colspan="2"><textarea name="permgroupintro" cols="50" rows="6"></textarea></td>
  </tr>
  <tr>
    <td colspan="2" align="center" nowrap ><input type="submit" class="inputbutton" value="保 存" />
   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="reset" class="inputbutton" value="重 置" /></td>
  </tr>
</table>
</form>
<div id="buttondiv">
<img class="button" src="${contextpath}/images/unfold.gif" onClick="closeopen()" />
<img class="button" src="${contextpath}/images/selectall.gif" onClick="closeopen()" />
<img class="button" src="${contextpath}/images/abolishall.gif" onClick="closeopen()" />
</div>

<div id="treebox" style="width:300px;height:490px;background-color:#fff;border:4px solid Silver;float:left;"></div>
<script>
	var xmlstring = document.getElementById("xmlstring").textContent;
			tree = new dhtmlXTreeObject("treebox","100%","100%",0);  //创建新对象
			tree.setImagePath("${contextpath}/js/dhtmlxtree/imgs/csh_bluebooks/");  //设置图片路径
			tree.setSkin('dhx_skyblue');  //加载皮肤
			tree.enableCheckBoxes(true);  //是否允许选中
			tree.enableDragAndDrop(false); //是否支持拖曳操作
			tree.enableThreeStateCheckboxes(true); //允许三种状态的复选框（全选、不选、部分选中）
			//tree.enableTreeLines(true);  //设置是否显示树线，默认为显示（true）
			//tree.enableTreeImages(true);  //设置是否允许显示树图片，默认为显示（true）
			tree.enableHighlighting(true);  //设置是否允许选中节点名称高亮显
			
			//tree.enableThreeStateCheckboxes(true);
			tree.setStdImages("book_titel.gif","tombs.gif","iconSafe.gif");  //设置节点图片，没有子节点时的图片，节点关闭时的图片，节点打开时的图片

			
			tree.attachEvent("onClick",treeClick);  //点击事件
			
			//tree.setDragBehavior(true, false);  //设置拖曳方式

			
			//tree.setDataMode(XML);  //设置传输方式JSON ，XML ，CSV 
			tree.loadXML("${contextpath}/security/permissiongroup_getTreeXmlDataAjax.action");  //加载XML数据，也可以是服务端路径
			//var aa = "<?xml version='1.0' encoding='UTF-8'?> <tree id='0'> <item text='基本信息' id='books'  im0='tombs.gif' im1='tombs.gif' im2='iconSafe.gif' call='1' select='1'></item></tree>";
			//tree.loadXMLString(aa);  //加载XML字符串
			//tree.enableSmartXMLParsing(true);  //智能解析XML
			//以下两句代码异步加载XML数据
			//tree.setXMLAutoLoading("${contextpath}/security/permissiongroup_getTreeXmlDataAjax.action");
			//tree.loadXML("${contextpath}/security/permissiongroup_getTreeXmlDataAjax.action?id=0");  //先加载一级Tree节点，然后再异步加载子节点数据
			tree.getXMLState();  //得到XML的加载状态
			//tree.closeAllItems(0);  //3.0默认是全部展开的，这段代码通过其方法来使其全部合并
			//tree.autoScroll;
			
			//选中事件
			var data = new Array();
			function treeClick(currentNodeId)
			{
				//alert(tree.getOpenState("books"));

				//alert(tree.getParentId(currentNodeId));  //获取父节点ID
				//alert(tree.getItemText(currentNodeId));  //获取节点名称
				//tree.setUserData(currentNodeId,"url","aaa");  //设置用户自定义数据
				//alert(tree.getUserData(currentNodeId, "url"));  //获取用户自定义数据，貌似只能得到设置的数据，而不能得到XML中的用户自定义数据
				//tree.getAllCheckedBranches();  //得到所有选中的节点的ID，很有用
				alert(tree.getAllChecked());  //得到所有被选中的节点
				alert(tree.getAllCheckedBranches());  //获取所有被选中节点id，包括第三种状态的节点（部分选中的节点）
				//alert(tree.getAllChecked());  //获取所有被选中节点id，不包括第三中状态的节点（部分选中的节点）
			
			
			//						if (document.getElementById("currentNodeId").checked == true)
			//						{
			//							alert(currentNodeId);
			//						}
				//data.input
			}
			
			//自定义方法
			//					dhtmlXTreeObject.prototype.getFirstNodeId =function()
			//					{
			//						var tempId = this.rootId;
			//						var temp=this._globalIdStorageFind(tempId);
			//						if(temp)return temp.childNodes[0].id;
			//						else return "";
			//					};
			
			//					tree._openItem(0);
			//alert(tree.getAllChecked());
			//					alert(tree.onCheckBoxClick(tree.getAllChecked()));
			//alert(tree.getAllFatItems);
			
			
			
			//					var data = new Array();
			//					data = tree.checkArray;
			//					data = getAllChecked();
			//					for (var i=0; i<data.length; i++)
			//					{
			//						alert(data[i]);
			//					}

			var state = 0;
			function closeopen()
			{
				if(state%2 == 0)
				{
					tree._xopenAll(tree._globalIdStorageFind('0'));  //0，是XML中配置的根节点ID，和创建对象时最后一个参数要一致
				}
				else
				{
					tree._xcloseAll(tree._globalIdStorageFind('0'));
				}
				state++;
			}
			
			//显示-隐藏
			function hidenshow()
			{
				tree._HideShow(tree._globalIdStorageFind('0'),0);  //显示或隐藏树	
			}
				
</script>
</body>
</html>
